<template>
	<!-- 我的错题、我的收藏 -->
	<view class="pd-30">
		<my-switch-navbar :activeTab.sync="activeTab" :tabName="tabName"></my-switch-navbar>
		<!-- <my-scroll-view scroll-y refresher-enabled :init="init"> -->

		<view class="padding-btm">
			<template v-if="paperList.list">
				<uni-swipe-action>
					<uni-swipe-action-item class="noticeSwipe" @click="delNotice($event, item, index)" v-for="(item, index) in paperList.list" :key="index" :right-options="options">
						<view class="paper-item" @click="historyClick(item)">
							<view class="name">
								<text class="content">{{ item.paperName }}</text>
								<!-- 历史记录显示分数 -->
								<text :class="['score', item.score >= 60 && 'pass']">{{ item.rights || 0 }}%</text>
							</view>
							<view class="info" v-if="!$scopedSlots.info">
								<image :src="require('../../static/icon/clock.png')"></image>
								<text>提交时间：{{ item.endTime }}</text>
								<image class="wrongIcon" :src="require('../../static/icon/count.png')"></image>
								<text>{{ title }}数量：{{ item.errorQueCou }}</text>
							</view>
							<!-- 自定义底部信息 -->
							<view class="info"><slot name="info" v-bind="item"></slot></view>
						</view>
					</uni-swipe-action-item>
				</uni-swipe-action>
			</template>
			<u-loadmore v-show="isShowLoadMore" icon-type="flower" bg-color="#f5f5f5" :status="status" @loadmore="getWrongPaper()" :margin-top="20" />
			<my-empty v-if="isempty"></my-empty>
		</view>
		<!-- </my-scroll-view> -->
	</view>
</template>

<script>
import exam from '../../mixins/exam.js';

export default {
	mixins: [exam],
	data() {
		return {
			activeTab: 0,
			isempty: false, //是否为空
			module: {
				tabName: ['系统任务', '老师任务'],
				title: '错题',
				api: {
					subject: '/app/mine/getTaskHistoryList'
				},
				answerPageSetting: {
					navTitle: '我的错题',
					backHandler: 'emptyRightAnswer'
				}
			},
			moudleName: '',
			paperList: {
				isLastPage: false,
				list: [],
				pageNo: 1
			},
			options: [
				{
					text: '删除',
					style: {
						backgroundColor: '#ef4c3a'
					}
				}
			],
			status: 'loadmore'
		};
	},
	onLoad() {
		this.moudleName = 0;
		this.init();
	},
	onReachBottom() {
		if (!this.paperList.isLastPage) {
			this.getWrongPaper();
		}
	},
	watch: {
		activeTab(e) {
			this.init();
		}
	},
	computed: {
		tabName() {
			return this.module.tabName;
		},
		title() {
			return this.module.title;
		},
		startAnswerApiParams() {
			return this.module.startAnswerApiParams;
		},
		answerPageSetting() {
			return this.module.answerPageSetting;
		},
		list() {
			return this.paperList.list;
		},
		isLastPage() {
			return this.paperList.isLastPage;
		}
	},
	methods: {
		delNotice(e, item, index) {
			let ids2 = [item.id];
			let pageData = {
				ids: ids2,
				type: this.activeTab + 1
			};
			// 删除通知
			this.request.post('/web/student/student/mine/deleteTaskHistory', pageData).then(res => {
				this.paperList.list.splice(index, 1);
				uni.showToast({
					icon: 'none',
					title: '删除成功！'
				});
			});
		},
		init() {
			this.paperList.isLastPage = false;
			this.paperList.list = [];
			this.paperList.pageNo = 1;
			this.status = 'loadmore';
			return this.getWrongPaper();
		},
		getWrongPaper() {
			const { list, pageNo } = this.paperList;
			this.status = 'loading';
			let pageData = {
				pageNo,
				type: this.activeTab + 1
			};
			return new Promise((resolve, reject) => {
				this.request
					.post('/app/mine/getTaskHistoryList', pageData)
					.then(res => {
						const { isLastPage, list: newList } = res;
						if (!newList) return;
						this.paperList.list = this.paperList.list.concat(newList);
						this.paperList.isLastPage = isLastPage;
						if (this.paperList.list.length == 0) {
							this.isempty = true;
						} else {
							this.isempty = false;
						}
						if (isLastPage) this.status = 'nomore';
						else this.paperList.pageNo++;
						resolve();
					})
					.catch(reject)
					.finally(() => {
						this.status !== 'nomore' && (this.status = 'loadmore');
					});
			});
		},
		historyClick(data) {
			const paperid = data.paperId;
			const apiSetting = { isClock: 1, paperid, isSign: true };
			let upid = data.upid;
			let achievementPageReload = true;
			let achievementPageReexamHander = null;
			this.signResult({ upid, status: 2 }, achievementPageReexamHander, achievementPageReload, 'navigateTo');
		}
	}
};
</script>
<style>
page {
	background: #f5f5f5;
}
</style>
<style scoped lang="scss">
/deep/.button-group--right {
	height: 82px;
}
.noticeSwipe {
	margin-bottom: 16upx;
}
.paper-item {
	height: 150upx;
	padding: 35upx 30upx;
	margin-bottom: 0;
	/deep/.name {
		margin-bottom: 20upx !important;
		.content {
			height: 75upx;
			line-height: 75upx;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			display: inline-block;
			margin-right: 20px;
		}
	}
}
.info {
	text {
		height: 30upx;
		line-height: 30upx;
		overflow: hidden;
		max-width: 60%;
	}
}
</style>
